package com.deercrowing.takeaway.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.deercrowing.takeaway.vo.DishesItemVO;
import com.deercrowing.takeaway.vo.SetmealsPageVO;
import org.apache.ibatis.annotations.Mapper;
import com.deercrowing.takeaway.entity.SetmealsEntity;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;


/**
 * 套餐表(Setmeal)表数据库访问层
 *
 * @author guoyongxiang
 * @since 2024-07-11 14:34:12
 */
@Mapper
public interface SetmealsMapper extends BaseMapper<SetmealsEntity> {
    /**
     * 搜索所有数据
     *
     * @return
     */
    @Select("select * from tb_setmeals")
    public List<SetmealsEntity> selectList();

    /**
     * 变更套餐起售\停用状态
     *
     * @param status
     * @param id
     */
    @Update("update tb_setmeals set status = #{status} where id = #{id}")
    public void updateByStatus(Short status, Integer id);

    /**
     * 统计分类下套餐数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from tb_setmeals where category_id = #{categoryId}")
    public int countIndex(Integer categoryId);

    /**
     * 统计套餐起售和禁售的数量
     *
     * @param dataMap
     * @return
     */
    public Integer countByMap(Map<String,Object> dataMap);

    /**
     * 根据条件搜索信息
     *
     * @param setmealsPageVO
     * @return
     */
    List<SetmealsEntity> selectListByCondition(SetmealsPageVO setmealsPageVO);

    /**
     * 根据套餐名称获取ID
     *
     * @param name
     * @return
     */
    @Select("select id from tb_setmeals where name = #{name}")
    Integer selectBySetmealId(String name);

    /**
     * 搜索套餐中菜品信息，以及套餐菜品的份数
     *
     * @param setmealId
     * @return
     */
    @Select("select d.name, sd.copies, d.image, d.description " +
            "from tb_setmeal_dish sd left join tb_dishes d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishesItemVO> selectDishBySetmealId(Long setmealId);

    /**
     * 根据分类ID搜索套餐
     *
     * @param category_id
     * @return
     */
    List<SetmealsEntity> selectListByCategory(Short category_id);

    /**
     * 根据条件统计套餐总数
     *
     * @param setmealsPageVO
     * @return
     */
    Integer countSetmealNum(SetmealsPageVO setmealsPageVO);
}

